/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.hibernate;

import com.knezevic.realestate.Member;
import com.knezevic.realestate.beans.MemberBean;
import com.knezevic.realestate.service.Members;
import java.io.Serializable;
import java.util.Collection;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author Nemanja
 */
public class MembersServiceHibernate implements Members{

    private final Session session;

    public MembersServiceHibernate(Session session) {
        this.session = session;
    }

    @Override
    public Member save(Member member) {
        return (Member) session.get(MemberBean.class, session.save(member));
    }

    @Override
    public void update(Member member) {
        session.saveOrUpdate(member);
    }

    @Override
    public void deleteMember(Member member) {
        session.delete(member);
    }

    @Override
    public Collection<Member> retrieve() {
        Criteria criteria = session.createCriteria(MemberBean.class);
        return criteria.list();
    }

    @Override
    public Collection<Member> retrieveRegularMembers() {
//        throw new UnsupportedOperationException("Not supported yet.");
        return null;
    }

    @Override
    public Member retrieve(Serializable id) {
        return (Member) session.get(MemberBean.class, id);
    }

}
